import axios from 'axios'

export const userToken = {
  namespaced: true,
  state: {
    token: localStorage.getItem('token') || ''
  },
  mutations: {
    SET_TOKEN(state, token) {
      state.token = token
      if (token) {
        localStorage.setItem('token', token)
      }
    }
  },
  actions: {
    async setToken({ commit }) {
      try {
        const response = await axios.get('http://127.0.0.1:4523/m1/5702810-5383946-default/api/login1')
        commit('SET_TOKEN', response.data.tokens)
      } catch (error) {
        console.error('Error fetching users:', error)
      }
    }
  }
}
